package com.example.myapplication.Utils;

import android.os.Bundle;
import android.os.Message;

import com.example.myapplication.MessagePacket.AddFriendPacket;
import com.example.myapplication.MessagePacket.Packet;
import com.example.myapplication.Main2Activity;

/**
 * @author gg_boy
 * @version $Rev$
 * @des ${接收消息刷新界面}
 * @updateAuther $Auther$
 * @updateDes ${TODO}
 */
public class RefreshInterface {
    public static void refresh(String strmsg, int showWhat, Packet packet){
        if(showWhat == 1){ // 1 represent not a add friend request
            Message message=new Message();
            message.what = Main2Activity.SHOW_MSG;
            Bundle bundle=new Bundle();
            bundle.putString("msg",strmsg);
            // 将Bundle对象放入message对象中，在MainActivity的Handler中通过msg这个键来获取对应的消息值
            message.setData(bundle);
            // 刷新MainActivity界面中的显示消息的文本框
            Main2Activity.getMainActivity().getMsghandler().sendMessage(message);
        }else if(showWhat == 2){ // 2 represent a add friend request,so need show the dialog
            AddFriendPacket addFriendPacket = (AddFriendPacket) packet;
            Message message = new Message();
            message.what = Main2Activity.SHOW_DIALOG;
            Bundle bundle=new Bundle();
            bundle.putString("sendUser",addFriendPacket.getSendUser());
            bundle.putString("receive", addFriendPacket.getReceiveUser());
            // 将Bundle对象放入message对象中，在MainActivity的Handler中通过msg这个键来获取对应的消息值
            message.setData(bundle);
            Main2Activity.getMainActivity().getMsghandler().sendMessage(message);
        }

    }
}
